<template>
  <Transition name="modal">
    <div v-if="show" class="modal">
      <div class="modal-container">
        <div class="modal-header">
          <slot name="header">
            <div class="modal-title">{{ title }}</div>
            <div class="modal-close" @click="$emit('update:show', false)">
              ×
            </div>
          </slot>
        </div>
        <div class="modal-body">
          <slot name="body">default body</slot>
        </div>
        <div class="modal-footer">
          <slot name="footer"> defaut footer </slot>
        </div>
      </div>
    </div>
  </Transition>
</template>

<script>
export default {
  props: {
    show: {
      type: Boolean,
    },
    title: {
      type: String,
      default: "提示",
    },
  },
};
</script>

<style scoped>
.modal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: rgba(0, 0, 0, 0.3);

  display: flex;
  align-items: center;
  justify-content: center;
}

.modal-container {
  width: 300px;
  padding: 20px 30px;
  background-color: #fff;
  transition: transform 0.5s ease;
}

.modal-header {
  display: flex;
  justify-content: space-between;
}

.modal-body {
  margin: 20px;
}

.modal-enter,
.modal-leave-to {
  opacity: 0;
}

.modal-enter-active,
.modal-leave-active {
  transition: all 0.5s ease;
}

.modal-enter-active .modal-container,
.modal-leave-active .modal-container {
  transform: scale(1.1);
}
</style>
